import QtQuick 2.0
import QtQuick.Controls 1.3
Rectangle {
    id: root00y
    width: 412
    height: 700
    color: app.getSystemThemeColor()
    transform: Scale { origin.x: 0; origin.y: 0; xScale: root.x_enl-0.3;yScale: root.y_enl-0.4}

    APPCloseMenu{
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.topMargin: 7
        anchors.rightMargin: 12
        onClose:{
            root00y.visible = false
        }
    }

    //标题
    Text
    {
        id:title
        text:"污染企业列表"
        font.family: "微软雅黑"
        font.pixelSize: 20
        color: "white"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: 17
    }

    Item{
        anchors.top: title.bottom
        anchors.topMargin: 10
        width: parent.width
        height: 30
        Text{
            id: cityText
            anchors.left: parent.left
            anchors.leftMargin: 10
            anchors.verticalCenter: parent.verticalCenter
            width: 30
            text: "城市"
            font.family: "黑体"
            font.pixelSize: 14
            color: "#FFF"
        }
        ComboBox{
            id: cityCombox
            anchors.left: cityText.right
            anchors.leftMargin: 10
            anchors.verticalCenter: parent.verticalCenter
            width: 80
            model: ListModel {
                    id: cbItems
                    ListElement { text: "全部";}
                    ListElement { text: "郑州";}
                    ListElement { text: "开封";}
                    ListElement { text: "洛阳";}
                    ListElement { text: "平顶山";}
                    ListElement { text: "安阳";}
                    ListElement { text: "鹤壁";}
                    ListElement { text: "新乡";}
                    ListElement { text: "焦作";}
                    ListElement { text: "濮阳";}
                    ListElement { text: "许昌";}
                    ListElement { text: "漯河";}
                    ListElement { text: "三门峡";}
                    ListElement { text: "南阳";}
                    ListElement { text: "商丘";}
                    ListElement { text: "信阳";}
                    ListElement { text: "周口";}
                    ListElement { text: "驻马店";}
                    ListElement { text: "济源";}
                }
            onCurrentIndexChanged:{
                var city = cbItems.get(currentIndex).text
                if(city === "全部"){
                    filterModel.clear()
                    listView.model = pollutionCompanyListModel
                    listView.useFilterModel = false
                }
                else{
                    filterModel.clear()
                    for(var i = 0; i < pollutionCompanyListModel.length; ++i){
                        if(pollutionCompanyListModel[i].city.indexOf(city) !== -1){
                            filterModel.append({"name": pollutionCompanyListModel[i].name, "city": pollutionCompanyListModel[i].city, "originalIndex": i})
                        }
                    }
                    listView.model = filterModel
                    listView.useFilterModel = true
                }
            }
        }

        Text{
            id: companyName
            anchors.left: cityCombox.right
            anchors.leftMargin: 10
            anchors.verticalCenter: parent.verticalCenter
            width: 30
            text: "名称"
            font.family: "黑体"
            font.pixelSize: 14
            color: "#FFF"
        }

        TextField{
            id: companyNameField
            anchors.left:companyName.right
            anchors.leftMargin: 10
            anchors.verticalCenter: parent.verticalCenter
            width: 120
            font.family: "黑体"
            font.pixelSize: 14
            placeholderText: "请输入企业名称"
            onDisplayTextChanged: {
                filterModel.clear()
                var companyNameStr = companyNameField.displayText;
                if(companyNameStr === ""){
                    listView.model = pollutionCompanyListModel
                    listView.useFilterModel = false
                }
                else{
                    for(var i = 0; i < pollutionCompanyListModel.length; ++i){
                        if(pollutionCompanyListModel[i].name.indexOf(companyNameStr) !== -1){
                            filterModel.append({"name": pollutionCompanyListModel[i].name, "city": pollutionCompanyListModel[i].city, "originalIndex": i})
                        }
                    }
                    listView.model = filterModel
                    listView.useFilterModel = true
                }

            }
        }

    }


    ListModel{
        id: filterModel
    }

    ScrollView{
        anchors.top: title.bottom
        anchors.topMargin: 40
        width: parent.width
        height: parent.height
        ListView{
            id: listView
            width: parent.width
            model: pollutionCompanyListModel
            property bool useFilterModel: false
            delegate: Rectangle{
                width: parent.width
                height: 20
                color: index % 2 == 0 ? "#888" : "#444"
                Text{
                    text: name
                    font.family: "黑体"
                    color: "#FFF"
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 30
                    MouseArea{
                        anchors.fill: parent
                        hoverEnabled: true
                        onEntered: {
                            parent.color = "#5be7c4"
                        }
                        onExited: {
                            parent.color = "#FFF"
                        }
                        onClicked: {
                            if(!listView.useFilterModel){
                                app.slotGotoPollutionCompany(index)
                            }
                            else{
                                app.slotGotoPollutionCompany(originalIndex)
                            }

                        }
                    }
                }
            }
        }
    }

}

